home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 30
/
Mac Magazin and MacEasy Magazine CD - Issue 30.iso
/
utilities
/
Mac OS X
/
Flurry
/
Flurry source
/
Source Folder
/
Spark.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2002-01-25
|
5KB
|
192 lines
// Spark.cpp: implementation of the Spark class.
//
//////////////////////////////////////////////////////////////////////
#include "std.h"
#include "Spark.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Spark::Spark()
{
}
Spark::~Spark()
{
}
void Spark::Draw()
{
return;
float width,sx,sy;
float w,z;
width = 60000.0f * sys_glWidth / 1024.0f;
z = position[2];
sx = position[0] * sys_glWidth / z + sys_glWidth * 0.5f;
sy = position[1] * sys_glWidth / z + sys_glHeight * 0.5f;
w = width*4.0f / z;
float screenx = sx;
float screeny = sy;
const float black[4] = {0.0f,0.0f,0.0f,1.0f};
glPushMatrix();
glTranslatef(screenx,screeny,0.0f);
float scale = w/50.0f;
glScalef(scale,scale,0.0f);
float a;
float c = 0.0625f;
for (int k=0;k<12;k++)
{
a = ((float) (rand() % 3600)) / 10.0f;
glRotatef(a,0.0f,0.0f,1.0f);
glBegin(GL_QUAD_STRIP);
glColor4fv(black);
glVertex2f(-3.0f,0.0f);
a = 2.0f + (float) (rand() & 255) * c;
glVertex2f(-3.0f,a);
glColor4fv(color);
glVertex2f(0.0f,0.0f);
glColor4fv(black);
glVertex2f(0.0f,a);
glVertex2f(3.0f,0.0f);
glVertex2f(3.0f,a);
glEnd();
}
glPopMatrix();
}
#define BIGMYSTERY 1800.0
#define MAXANGLES 16384
void Spark::Update()
{
// const float rotationsPerSecond = (float) (2.0*PI*TICKSPERSECOND/MAXANGLES);
const float rotationsPerSecond = (float) (2.0*PI*fieldSpeed/MAXANGLES);
double thisPointInRadians;
double thisAngle = fTime*rotationsPerSecond;
float cf;
int i;
double tmpX1,tmpY1,tmpZ1;
double tmpX2,tmpY2,tmpZ2;
double tmpX3,tmpY3,tmpZ3;
double tmpX4,tmpY4,tmpZ4;
double rotation;
double cr;
double sr;
float cycleTime = 20.0f;
if (currentColorMode == rainbowColorMode)
{
cycleTime = 1.5f;
}
else if (currentColorMode == tiedyeColorMode)
{
cycleTime = 4.5f;
}
else if (currentColorMode == cyclicColorMode)
{
cycleTime = 20.0f;
}
else if (currentColorMode == slowCyclicColorMode)
{
cycleTime = 120.0f;
}
float colorRot = (float) (2.0*PI/cycleTime);
float redPhaseShift = 0.0f; //cycleTime * 0.0f / 3.0f
float greenPhaseShift = cycleTime / 3.0f;
float bluePhaseShift = cycleTime * 2.0f / 3.0f ;
float baseRed;
float baseGreen;
float baseBlue;
float colorTime = fTime;
if (currentColorMode == whiteColorMode)
{
baseRed = 0.1875f;
baseGreen = 0.1875f;
baseBlue = 0.1875f;
}
else if (currentColorMode == multiColorMode)
{
baseRed = 0.0625f;
baseGreen = 0.0625f;
baseBlue = 0.0625f;
}
else if (currentColorMode == darkColorMode)
{
baseRed = 0.0f;
baseGreen = 0.0f;
baseBlue = 0.0f;
}
else
{
if (currentColorMode < slowCyclicColorMode)
{
colorTime = (currentColorMode / 6.0f) * cycleTime;
}
else
{
colorTime = fTime;
}
baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f);
baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f);
baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f);
}
float old[3];
for (i=0;i<3;i++)
{
old[i] = position[i];
}
cf = ((float) (cos(7.0*((fTime)*rotationsPerSecond))+cos(3.0*((fTime)*rotationsPerSecond))+cos(13.0*((fTime)*rotationsPerSecond))));
cf /= 6.0f;
cf += 2.0f;
thisPointInRadians = 2.0 * PI * (double) mystery / (double) BIGMYSTERY;
color[0] = baseRed + 0.0625f * (0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + (float) sin((7.0 * (thisPointInRadians + thisAngle))));
color[1] = baseGreen + 0.0625f * (0.5f + (float) sin(((thisPointInRadians) + thisAngle)));
color[2] = baseBlue + 0.0625f * (0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle))));
position[0] = fieldRange * cf * (float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle)));
position[1] = fieldRange * cf * (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle)));
position[2] = fieldRange * (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle))));
rotation = thisAngle*0.501 + 5.01 * (double) mystery / (double) BIGMYSTERY;
cr = cos(rotation);
sr = sin(rotation);
tmpX1 = position[0] * cr - position[1] * sr;
tmpY1 = position[1] * cr + position[0] * sr;
tmpZ1 = position[2];
tmpX2 = tmpX1 * cr - tmpZ1 * sr;
tmpY2 = tmpY1;
tmpZ2 = tmpZ1 * cr + tmpX1 * sr;
tmpX3 = tmpX2;
tmpY3 = tmpY2 * cr - tmpZ2 * sr;
tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance;
rotation = thisAngle*2.501 + 85.01 * (double) mystery / (double) BIGMYSTERY;
cr = cos(rotation);
sr = sin(rotation);
tmpX4 = tmpX3 * cr - tmpY3 * sr;
tmpY4 = tmpY3 * cr + tmpX3 * sr;
tmpZ4 = tmpZ3;
position[0] = (float) tmpX4 + RandBell(5.0f*fieldCoherence);
position[1] = (float) tmpY4 + RandBell(5.0f*fieldCoherence);
position[2] = (float) tmpZ4 + RandBell(5.0f*fieldCoherence);
for (i=0;i<3;i++)
{
delta[i] = (position[i] - old[i])/fDeltaTime;
}
}